package com.study.demo.api.login;

import com.study.demo.bean.CookieData;
import com.study.demo.components.retrofit.FastJsonConverterFactory;

import io.reactivex.Observable;
import io.reactivex.schedulers.Schedulers;
import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;

/**
 * Created by sll on 2015/3/8.
 */
public class CookieApi {
  private CookieService mCookieService;

  private static final String BASE_URL = "http://passport.hupu.com/pc/login/";

  public CookieApi(OkHttpClient mOkHttpClient) {
    Retrofit retrofit =
        new Retrofit.Builder().addConverterFactory(FastJsonConverterFactory.create())
            .client(mOkHttpClient)
            .baseUrl(BASE_URL)
            .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
            .build();
    mCookieService = retrofit.create(CookieService.class);
  }

  public Observable<CookieData> login(String userName, String passWord) {
    return mCookieService.login(userName, passWord).subscribeOn(Schedulers.io());
  }
}
